<template>
  <page-frame>
    <div class="servicePlan">
      <div class="toptitle ">
        <div class="left">{{currentTitleName}} - <span>{{currentMemberName}}</span></div>
        <div class="right">
          <div class="btns">
            <el-button class="lightGreenBtn button-style" @click="makeServicePlan">提交计划</el-button>
            <el-button class="button-style" @click="back">返回</el-button>
          </div>
        </div>
      </div>
      <div class="borderT"></div>
      <div class="service-plan-main">
        <div class="panel">
          <div class="panel-title">
            <div class="grid-content bg-purple">会员能力评估结果</div>
          </div>
          <div class="panel-content">
            <el-table
              :data="setResultInfoDTOList"
              border
              highlight-current-row
              style="width: 80%">
              <el-table-column
                prop="setName"
                label="评估项目"
              >
              </el-table-column>
              <el-table-column
                prop="resultValue"
                label="评估得分"
              >
              </el-table-column>
              <el-table-column
                prop="resultName"
                label="评估等级"
              >
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="inputInfor">
          <el-row>
            <el-col :span="8">
              <div class="el-form-item">
                <label style="font-size: 14px;">照护等级:</label>
                <el-select placeholder="请选择新照护等级" v-model="servicePlan.lid" disabled>
                  <el-option
                    v-for="item in careLevelOptions"
                    :label="item.lname"
                    :value="item.lid">
                  </el-option>
                </el-select>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="el-form-item">
                <label style="font-size: 14px;">评估结论:</label>
                <el-input
                  type="text"
                  v-model="resultName"
                  class="serviceNeeds"
                  disabled
                ></el-input>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="el-form-item">
                <label style="font-size: 14px;">服务周期:</label>
                <el-date-picker
                  v-model="cycleDate"
                  type="daterange"
                  align="right"
                  placeholder="选择日期范围"
                >
                </el-date-picker>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="el-form-item">
                <label style="font-size: 14px;">评估备注:</label>
                <el-input
                  type="text"
                  disabled
                  v-model="setAssessmentResultDTO.comment"
                  class="serviceNeeds"
                ></el-input>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="el-form-item">
                <label style="font-size: 14px;vertical-align: top;">护理重点:</label>
                <el-input
                  type="textarea"
                  placeholder="请输入服务需求"
                  v-model="servicePlan.carePoint"
                  class="serviceNeeds"
                >
                </el-input>
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="panel">
          <div class="panel-title">
            <div class="grid-content bg-purple">制定服务计划</div>
          </div>
          <div class="panel-content">
            <el-collapse v-model="activeNames" @change="handleChange">
              <el-collapse-item title="计划套餐" name="1">
                <div v-for="serviceItem in serviceComboItem">
                  <el-row :gutter="10" style="margin: 30px 60px 5px 60px;width: auto;">
                    <el-col :span="5">
                      <label>套餐名称:</label>
                      <span>{{serviceItem.comboName}}</span>
                    </el-col>
                    <el-col :span="5">
                      <label>套餐价格:</label>
                      <span>{{serviceItem.price}}</span>
                    </el-col>
                  </el-row>
                  <el-table
                    :data="serviceItem.servicePlanItemServiceListDTOs"
                    border
                    style="margin: 5px 60px 30px 60px;width: auto;">
                    <el-table-column
                      prop="serviceName"
                      label="服务项目"
                    >
                    </el-table-column>
                    <el-table-column
                      label="工作时间"
                    >
                      <template scope="scope">
                        <div style="width:100%;height:100%;">
                          <p v-if="scope.row.period==2&&scope.row.month!=''"><span>每月</span> {{scope.row.servicePlanItemServiceTimetDTO.month}} <span>日</span> </p>
                          <p>{{scope.row.servicePlanItemServiceTimetDTO.week}}</p>
                          <p v-for="time in scope.row.servicePlanItemServiceTimetDTO.serviceTime">{{time}}</p>
                          <el-button type="text" @click.stop = "handleTimeClick(scope.row)">工作时间</el-button>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="频次">
                      <template scope="scope">
                        <el-row>
                          <el-col :span="14">
                            <el-select v-model="scope.row.period" placeholder="" >
                              <el-option
                                v-for="item in frequencyList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                              </el-option>
                            </el-select>
                          </el-col>
                          <el-col :span="9" v-if="scope.row.period==2||scope.row.period==1">
                            <el-input v-model="scope.row.num"></el-input>
                          </el-col>
                          <el-col :span="1" v-if="scope.row.period==2||scope.row.period==1"><span class="frequencyUnit">次</span></el-col>
                        </el-row>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>

              <el-collapse-item title="自选项目" name="1">
                <el-table
                  :data="serviceFreeItem"
                  border
                  style="margin: 5px 60px 30px 60px;width: auto;">
                  <el-table-column
                    prop="serviceName"
                    label="服务项目"
                  >
                  </el-table-column>
                  <el-table-column
                    label="工作时间"
                  >
                    <template scope="scope">
                      <div style="width:100%;height:100%;">
                        <p v-if="scope.row.period==2&&scope.row.month!=''"><span>每月</span> {{scope.row.servicePlanItemServiceTimetDTO.month}} <span>日</span> </p>
                        <p>{{scope.row.servicePlanItemServiceTimetDTO.week}}</p>
                        <p v-for="time in scope.row.servicePlanItemServiceTimetDTO.serviceTime">{{time}}</p>
                        <el-button type="text" @click.stop = "handleTimeClick(scope.row)">工作时间</el-button>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="频次">
                    <template scope="scope">
                      <el-row>
                        <el-col :span="14">
                          <el-select v-model="scope.row.period" placeholder="" >
                            <el-option
                              v-for="item in frequencyList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                            </el-option>
                          </el-select>
                        </el-col>
                        <el-col :span="9" v-if="scope.row.period==2||scope.row.period==1">
                          <el-input  v-model="scope.row.num"></el-input>
                        </el-col>
                        <el-col :span="1" v-if="scope.row.period==2||scope.row.period==1"><span class="frequencyUnit">次</span></el-col>
                      </el-row>
                    </template>
                  </el-table-column>
                </el-table>
              </el-collapse-item>
            </el-collapse>
          </div>
        </div>
      </div>

      <!--修改次数弹框-->
      <el-dialog
        :title="titleName"
        :visible.sync="dialogVisible"
        size="small"
        >
        <el-form :model="timeRuleForm" :rules="rules" ref="timeRuleForm" label-width="100px" class="demo-ruleForm">
          <!--服务项目-->
          <el-form-item v-if="currentPeriod==0||currentPeriod==3" label="服务项目" prop="serviceName">
            <el-input disabled v-model="timeRuleForm.serviceName"></el-input>
          </el-form-item>
          <!--周历-->
          <el-form-item v-if="currentPeriod==1" label="周历" prop="weeks">
            <el-checkbox-group v-model="timeRuleForm.weeks" @change="weekChange">
              <el-checkbox label="1">周一</el-checkbox>
              <el-checkbox label="2">周二</el-checkbox>
              <el-checkbox label="3">周三</el-checkbox>
              <el-checkbox label="4">周四</el-checkbox>
              <el-checkbox label="5">周五</el-checkbox>
              <el-checkbox label="6">周六</el-checkbox>
              <el-checkbox label="0">周日</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <!--月历-->
          <el-form-item
            v-if="currentPeriod==2"
            v-for="(month, index) in timeRuleForm.months"
            :label="'月历'"
          >
            <el-row>
              <el-col :span="2" style="text-align:center;">每月</el-col>
              <el-col :span="4">
                <el-input v-model="timeRuleForm.months[index]" @change="monthChange" style="width:100%!important;text-align: center"></el-input>
              </el-col>
              <span>日</span>
              <el-button type="text" v-if="timeRuleForm.months.length!=1" @click.prevent="removeMonth(month)">删除</el-button>
              <el-button type="text" v-if="index==timeRuleForm.months.length-1" @click.prevent="addMonth(month)">增加</el-button>
            </el-row>
          </el-form-item>
          <!--时间-->
          <el-form-item
            v-for="(time, index) in servicePlanItemTimeDTOList"
            :label="'选择时间'"
          >
            <el-time-picker
              is-range
              format="HH:mm:ss"
              v-model="servicePlanItemTimeDTOList[index]"
              placeholder="选择时间"
              @change="selectTime">
            </el-time-picker>
            <el-button type="text" v-if="servicePlanItemTimeDTOList.length!=1" @click.prevent="removeTime(time)">删除</el-button>
            <el-button type="text" v-if="index==servicePlanItemTimeDTOList.length-1" @click.prevent="addTime">新增</el-button>
          </el-form-item>
          <p style="padding-left:100px;" v-if="currentPeriod!=0">服务总次数：<span>{{timeRuleForm.num}}</span> 次</p>
          <p style="padding-left:100px;" v-if="currentPeriod==1">
            已勾选次数 <span style="color:red;">（当日工作次数 * 周历天数）</span>：<span>{{weekResult}}</span>  次
          </p>
          <p style="padding-left:100px;" v-if="currentPeriod==2">
            已勾选次数 <span style="color:red;">（当日工作次数 * 月历天数）</span>：<span>{{monthResult}}</span>  次
          </p>
          <p style="padding-left:100px;" v-if="currentPeriod!=0">
            请将「已勾选频次」和「服务总次数」保持一致
          </p>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="queryTime">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </page-frame>
</template>

<script>
  import servicePlanApi from '../../service/serManagement/servicePlanApi';
  import commonJs from '../../config/common';
  export default {
    data () {
      return {
        dialogVisible: false,
        currentTitleName:'制定服务计划',
        titleName:'次数修改',
        timeRuleForm:{
          weeks:null,
          months: [{

          }],
          servicePlanItemTimeDTOList:[],
        },
        rules:{},
        servicePlanItemTimeDTOList:[],
        serviceName:'',
        currentPeriod:null,
        oldPlanItemId:null,
        currentPlanItemId:null,
        weekResult:null,
        monthResult:null,
        TabsValue:'1',
        currentPlanId:null,
        currentMemberName:"",
        careLevelOptions:[],
        serviceTeam:false,
        activeNames: ['1'],
        teamId:null,
        serviceNeeds:"",
        frequencyList:[{
          value:3,
          label:'任意'
        },{
          value:0,
          label:'每天'
        },{
          value:1,
          label:'每周'
        },{
          value:2,
          label:'每月'
        }],
        cycleDate:[],
        servicePlan:{
          carePoint: "",
          dateEnd: "",
          dateStart: "",
          date:[],
          lid: null,
          planId: 0,
          servicePlanItemListDTO: {
            servicePlanItemComboListDTOs: [
              {
                "comboId": 0,
                "comboName": "",
                "price": 0,
                "servicePlanItemServiceListDTOs": [
                  {
                    "period": 0,
                    "periodNum":"",
                    "serviceId": 0,
                    "serviceName": "",
                    "timeEnd": "",
                    "timeStart": "",
                    "time":[],
                    "tmId": 0
                  }
                ]
              }
            ],
            servicePlanItemServiceListDTOs: [
              {
                "period": 0,
                "periodNum":"",
                "serviceId": 0,
                "serviceName": "string",
                "timeEnd": "",
                "timeStart": "",
                "tmId": 0
              }
            ]
          }
        },
        serviceComboItem:[
          {
            "comboId": 0,
            "comboName": "",
            "price": 0,
            "servicePlanItemServiceListDTOs": [
              {
                "period": 0,
                "periodNum":"",
                "serviceId": 0,
                "serviceName": "",
                "timeEnd": "",
                "timeStart": "",
                "time":[],
                "tmId": 0
              }
            ]
          }
        ],
        serviceFreeItem:[
          {
            "period": 0,
            "periodNum":"",
            "serviceId": 0,
            "serviceName": "",
            "timeEnd": "",
            "timeStart": "",
            "time":[],
            "tmId": 0
          }
        ],
        submitPlan:{
          "carePoint": "",
          "dateEnd": "",
          "dateStart": "",
          "planId": 0,
          "servicePlanAppointTeamDTOs": [
            {
              "period": 0,
              "planItemId": 0,
              "serviceId": 0,
              "serviceName": "",
              "timeEnd": "",
              "timeStart": "",
              "tmId": null
            }
          ]
        },
        setResultInfoDTOList:[],
        setAssessmentResultDTO:[],
        resultName:"",
      }
    },
    methods: {
      init() {
        let self = this;
        self.currentPlanId = self.$route.params.rowObj.planId;
        self.currentMemberName = self.$route.params.rowObj.memberName;
        self.getAssessResult(self.$route.params.rowObj.memberId);
        self.getServicePlanDetails();
        this.getCareLevel();
        if(self.$route.params.way==0){//调整服务计划
          this.currentTitleName = '调整服务计划';
        }else{//制定服务计划
          this.currentTitleName = '制定服务计划';
        }
      },
      /**
       * 改变时间
       */
      selectTime(){
        if(this.currentPeriod==1){//周
          this.weekChange();
        }else if(this.currentPeriod==2){//月
          this.monthChange();
        }
      },
      /**
       * 周的个数/时间变化
       */
      weekChange(){
        //周历有效个数
        let weekLen = 0;
        for(let i=0;i<this.timeRuleForm.weeks.length;i++){
          if(this.timeRuleForm.weeks[i]==''||this.timeRuleForm.weeks[i]==null){

          }else{
            weekLen++;
          }
        }

        if(this.servicePlanItemTimeDTOList.length==1){
          if(this.servicePlanItemTimeDTOList[0]==''||this.servicePlanItemTimeDTOList[0]==null){
            this.weekResult = 0;
          }else{
            this.weekResult = weekLen*1;
          }
        }else{
          let num = 0;
          for(let i=0;i<this.servicePlanItemTimeDTOList.length;i++){
            if(this.servicePlanItemTimeDTOList[i]==''||this.servicePlanItemTimeDTOList[i]==null){

            }else{
              num++;
            }
          }
          this.weekResult = weekLen*num;
        }
        if(this.weekResult>this.timeRuleForm.num){
          this.$message({
            message:'已勾选次数大于总次数',
            type:'warning'
          });
        }
      },
      /**
       * 修改频次
       */
      queryTime(){
        let self = this;
        let startTime = '';
        let endTime = '';
        let servicePlanItemDTO = self.timeRuleForm;
        servicePlanItemDTO.servicePlanItemTimeDTOList = [];
        for(let i=0;i<self.servicePlanItemTimeDTOList.length;i++){
          for(let k=0;k<self.servicePlanItemTimeDTOList[i].length;k++){
            if(k==0){
              startTime = commonJs.formatTime(self.servicePlanItemTimeDTOList[i][k]);
            }else{
              endTime = commonJs.formatTime(self.servicePlanItemTimeDTOList[i][k]);
            }
          }
          let time = {
            'startTime':startTime,
            "planItemId": self.currentPlanItemId,
            'endTime':endTime
          }
          servicePlanItemDTO.servicePlanItemTimeDTOList.push(time);
        }
        if(servicePlanItemDTO.period==1||servicePlanItemDTO.period==0){
          servicePlanItemDTO.months=[];
        }

        if(self.timeRuleForm.weeks.length==0&&self.currentPeriod==1){
          self.$message({
            message:'周历不能为空',
            type:'warning'
          });
          return false;
        }

        if(self.timeRuleForm.months.length==0&&self.currentPeriod==2){
          self.$message({
            message:'月历不能为空',
            type:'warning'
          });
          return false;
        }

        if(self.currentPeriod==1){//周
          if(self.weekResult>self.timeRuleForm.num){
            self.$message({
              message:'已勾选次数大于总次数',
              type:'warning'
            });
            return false;
          }
        }
        if(self.currentPeriod==2){//月
          if(self.monthResult>self.timeRuleForm.num){
            self.$message({
              message:'已勾选次数大于总次数',
              type:'warning'
            });
            return false;
          }
        }
        servicePlanApi.updatePlanTimeDetail(self.currentPlanItemId,servicePlanItemDTO).then(
          (response)=>{
            if(response.data.status==200){
              self.$message({
                message:'修改成功',
                type:'success'
              });
              self.dialogVisible = false;
              self.getServicePlanDetails();
            }else{
              self.$message({
                message:response.data.message,
                type:'error'
              });
            }
          }
        );
      },
      /**
       * 新增时间
       */
      addTime() {
        this.servicePlanItemTimeDTOList.push([]);
        if(this.currentPeriod==1){//周历
          this.weekChange();
        }else if(this.currentPeriod==2){
          this.monthChange();
        }
      },
      /**
       * 删除时间
       */
      removeTime(item) {
        var index = this.servicePlanItemTimeDTOList.indexOf(item)
        if (index !== -1) {
          this.servicePlanItemTimeDTOList.splice(index, 1)
        }
        if(this.currentPeriod==1){//周
          this.weekChange();
        }else if(this.currentPeriod==2){//月
          this.monthChange();
        }
      },
      /**
       * 月份/时间改变时 已勾选次数
       */
      monthChange(){
        let monthLen = 0;
        for(let i=0;i<this.timeRuleForm.months.length;i++){
          if(this.timeRuleForm.months[i]==''||this.timeRuleForm.months[i]==null){

          }else{
            monthLen++;
          }
        }

        if(this.servicePlanItemTimeDTOList.length==1){
          if(this.servicePlanItemTimeDTOList[0]==''||this.servicePlanItemTimeDTOList[0]==null){
            this.monthResult = 0;
          }else{
            this.monthResult = monthLen*1;
          }
        }else{
          let num = 0;
          for(let i=0;i<this.servicePlanItemTimeDTOList.length;i++){
            if(this.servicePlanItemTimeDTOList[i]==''||this.servicePlanItemTimeDTOList[i]==null){

            }else{num++}
          }
          this.monthResult = monthLen*num;
        }
        if(this.monthResult>this.timeRuleForm.num){
          this.$message({
            message:'已勾选次数大于总次数',
            type:'warning'
          });
        }
      },
      /**
       * 新增月历
       */
      addMonth() {
        this.timeRuleForm.months.push({});
        this.monthChange();
      },
      /**
       * 删除月历
       */
      removeMonth(item) {
        var index = this.timeRuleForm.months.indexOf(item)
        if (index !== -1) {
          this.timeRuleForm.months.splice(index, 1)
        }
        this.monthChange();
      },
      /**
       * 双击工作时间cell表格
       */
      handleTimeClick(row){
        this.dialogVisible =true;
        if(this.oldPlanItemId==this.currentPlanItemId&&this.oldPlanItemId!=null&&this.currentPlanItemId!=null){

        }else{//planItemId不相等清空弹框数据
          this.timeRuleForm.serviceName = '';
          this.timeRuleForm.weeks = [];
          this.timeRuleForm.months = [null];
          this.servicePlanItemTimeDTOList = [];
        }
        this.currentPeriod = row.period;
        this.serviceName = row.serviceName;
        this.currentPlanItemId = row.planItemId;
        this.oldPlanItemId = row.planItemId;
        this.getServicePlanTimeDetail(row.planItemId);

      },

      /**
       * 获取服务计划时间详情
       */
      getServicePlanTimeDetail(planItemId){
        let self = this;
        servicePlanApi.getPlanTimeDetail(planItemId).then(
          (response)=>{
            self.timeRuleForm = response.data.data;
            self.timeRuleForm.serviceName = self.serviceName;
            //时间转换
            if(self.timeRuleForm.servicePlanItemTimeDTOList.length==0){
              self.servicePlanItemTimeDTOList = [[]];
            }else{
              for(let i=0;i<self.timeRuleForm.servicePlanItemTimeDTOList.length;i++){
                self.servicePlanItemTimeDTOList[i] = [];
                self.servicePlanItemTimeDTOList[i].push(new Date('1970-01-01'+" "+self.timeRuleForm.servicePlanItemTimeDTOList[i].startTime));
                self.servicePlanItemTimeDTOList[i].push(new Date('1970-01-01'+" "+self.timeRuleForm.servicePlanItemTimeDTOList[i].endTime));
              }
            }

            if(self.servicePlanItemTimeDTOList.length==0){
              self.servicePlanItemTimeDTOList = [[]];
            }else if(self.servicePlanItemTimeDTOList.length==1){
              if(self.servicePlanItemTimeDTOList[0]==null||self.servicePlanItemTimeDTOList[0]==''){
                self.servicePlanItemTimeDTOList = [[]];
              }
            }else{
              self.servicePlanItemTimeDTOList = commonJs.formateTimeToArr(self.servicePlanItemTimeDTOList);
            }

            //如果月的数据为空，默认显示1号
            if(response.data.data.months.length==0){
              self.timeRuleForm.months = [null];
            }

            //如果服务总数为空，转换成0
            if(self.timeRuleForm.num==''){
              self.timeRuleForm.num=0;
            }
            self.weekChange();
            self.monthChange();
          },
          (response)=>{

          }
        );
      },

      /**
       * 根据memberId获取能力评估结果
       */
      getAssessResult(memberId){
        servicePlanApi.getAssessResultByMemberId(1,memberId).then(
          (response)=>{
          this.setResultInfoDTOList = response.data.data.setResultInfoDTOList;
        this.setAssessmentResultDTO = response.data.data.assessmentResultDTO;
        this.resultName=response.data.data.resultName;
      }
      );
      },
      /**
       * 获得照护等级
       */
      getCareLevel(){
        servicePlanApi.getCareLevel().then(
          (response)=>{
          this.careLevelOptions = response.data.data;
      }
      );
      },
      /**
       * 获得服务计划详情
       */
      getServicePlanDetails(){
        let self = this;
        servicePlanApi.getServicePlanDetails(self.currentPlanId).then(function(response){
          self.servicePlan = response.body.data;
          self.cycleDate = [];
          self.cycleDate[0] = self.servicePlan.dateStart;
          self.cycleDate[1] = self.servicePlan.dateEnd;
          self.serviceComboItem = self.servicePlan.servicePlanItemListDTO.servicePlanItemComboListDTOs;
          //计划套餐时间转换
          for(let j=0;j<self.serviceComboItem.length;j++){
            for(let i=0;i<self.serviceComboItem[j].servicePlanItemServiceListDTOs.length;i++){
              self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].time=[];
              self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].time[0] = self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].timeStart;
              self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].time[1] = self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].timeEnd;
              if(self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].tmType==0){
                //什么都不做
              }else{
                self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].tmIdArr.push(self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].tmType);
                self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].tmIdArr.push(self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].tmId);
              }
              //当收到的总次数为空(周/月) 转换成0
              if(self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].period==1||self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].period==2){
                if(self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].num==''){
                  self.serviceComboItem[j].servicePlanItemServiceListDTOs[i].num=0;
                }
              }
            }
          }
          self.serviceFreeItem = self.servicePlan.servicePlanItemListDTO.servicePlanItemServiceListDTOs;
          //自选项目时间转换
          for(let i=0;i<self.serviceFreeItem.length;i++){
            self.serviceFreeItem[i].time = [];
            self.serviceFreeItem[i].time[0] = self.serviceFreeItem[i].timeStart;
            self.serviceFreeItem[i].time[1] = self.serviceFreeItem[i].timeEnd;
            if(self.serviceFreeItem[i].tmType==0){
              //什么都不做
            }else{
              self.serviceFreeItem[i].tmIdArr.push(self.serviceFreeItem[i].tmType);
              self.serviceFreeItem[i].tmIdArr.push(self.serviceFreeItem[i].tmId);
            }
            //当收到的总次数为空(周/月) 转换成0
            if(self.serviceFreeItem[i].period==1||self.serviceFreeItem[i].period==2){
              if(self.serviceFreeItem[i].num==''){
                self.serviceFreeItem[i].num=0;
              }
            }
          }
        })
      },
      /**
       * 提交服务计划
       */
      makeServicePlan(){
        let self = this;
        self.submitPlan.carePoint = self.servicePlan.carePoint;
        self.submitPlan.dateStart = self.cycleDate[0];
        self.submitPlan.dateEnd = self.cycleDate[1];
        self.submitPlan.planId = self.currentPlanId;
        //计划套餐连接到数组里
        self.submitPlan.servicePlanAppointTeamDTOs = [];
        for(let i=0;i<self.serviceComboItem.length;i++){
          let item = self.serviceComboItem[i].servicePlanItemServiceListDTOs;
          for(let k=0;k<item.length;k++){
            self.submitPlan.servicePlanAppointTeamDTOs.push(item[k]);
          }
          //这里之所以没有使用concat拼接数组是因为它竟然没有效果,我也是醉了;
          //self.submitPlan.servicePlanAppointTeamDTOs.concat(item);
        }
        //自选套餐连接到数组里
        for(let i=0;i<self.serviceFreeItem.length;i++){
          self.submitPlan.servicePlanAppointTeamDTOs.push(self.serviceFreeItem[i]);
        }
        //赋值tmId
        for(let i=0;i<self.submitPlan.servicePlanAppointTeamDTOs.length;i++){
          self.submitPlan.servicePlanAppointTeamDTOs[i].tmId = self.submitPlan.servicePlanAppointTeamDTOs[i].tmIdArr[1];
        }
        if(self.$route.params.way==1){//制定服务计划
          servicePlanApi.makeServicePlan(self.submitPlan).then(function(response){
            self.$router.push({name: "servicePlanList"});
            self.$message({
              message: '提交计划成功',
              type: 'success'
            });
          })
        }else{//调整服务计划
          servicePlanApi.makeServicePlan(self.submitPlan).then(function(response){
            self.$router.push({name: "servicePlanList"});
            self.$message({
              message: '提交计划成功',
              type: 'success'
            });
          })
        }
      },
      /**
       * 返回
       */
      back(){
        this.$router.push({name:'servicePlanList'});
      },
      handleChange(){}
    },

    mounted: function () {
      this.init();
    },
  }
</script>
<style>
  .servicePlan .button-style {
    width: 90px;
  }
  .servicePlan .toptitle {
    position: relative;
  }
  .servicePlan .el-collapse,.servicePlan .el-table {
    width: 94%;
  }
  .servicePlan .el-table th > .cell {
    text-align: center;
    line-height: 50px;
  }
  .servicePlan .el-table td, .el-table th {
    height: 50px;
  }
  .servicePlan .inputInfor{
    padding-left: 15px;
  }
  .servicePlan .el-dialog .el-input{
    width:60%!important;
  }
</style>
